/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * JObjectPaletteFrame.java
 *
 * Created on 2010-maj-17, 11:38:15
 */

package foalvleditor.gui;

import foalvleditor.core.impl.LevelModel;
import foalvleditor.gameobjects.Bitmap;
import foalvleditor.gameobjects.GameObjectFactory;
import foalvleditor.gameobjects.GameObjectFactory.GameObjectType;
import java.awt.Point;

/**
 *
 * @author Mikael
 */
public class JObjectPaletteFrame extends javax.swing.JInternalFrame {

	/**
	 *
	 */
	private static final long serialVersionUID = 1L;
	private static final LevelModel levelModel=LevelModel.getInstance();

    /** Creates new form JObjectPaletteFrame */
    public JObjectPaletteFrame() {
        super();
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings({ "deprecation" })
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        addPlayerButton = new javax.swing.JButton();
        addEnemyButton = new javax.swing.JButton();
        addDoorButton = new javax.swing.JButton();
        addSpikeButton = new javax.swing.JButton();
        addLeverButton = new javax.swing.JButton();
        addPushButton = new javax.swing.JButton();
        addKeyButton = new javax.swing.JButton();
        addBlueBoxButton = new javax.swing.JButton();
        addRedBoxUpButton = new javax.swing.JButton();
        addRedBoxDownButton = new javax.swing.JButton();
        addWoodenBoxButton = new javax.swing.JButton();
        changeBackgroundComboBox = new javax.swing.JComboBox();

        setDefaultCloseOperation(javax.swing.WindowConstants.HIDE_ON_CLOSE);
        setIconifiable(true);
        setName("Form"); // NOI18N
        getContentPane().setLayout(new java.awt.GridLayout(2, 0));

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(foalvleditor.core.FoaLvlEditorApp.class).getContext().getActionMap(JObjectPaletteFrame.class, this);
        addPlayerButton.setAction(actionMap.get("addPlayer")); // NOI18N
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(foalvleditor.core.FoaLvlEditorApp.class).getContext().getResourceMap(JObjectPaletteFrame.class);
        addPlayerButton.setIcon(resourceMap.getIcon("addPlayerButton.icon")); // NOI18N
        addPlayerButton.setText(resourceMap.getString("addPlayerButton.text")); // NOI18N
        addPlayerButton.setToolTipText(resourceMap.getString("addPlayerButton.toolTipText")); // NOI18N
        addPlayerButton.setFocusable(false);
        addPlayerButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        addPlayerButton.setMinimumSize(new java.awt.Dimension(40, 40));
        addPlayerButton.setName("addPlayerButton"); // NOI18N
        addPlayerButton.setNextFocusableComponent(addEnemyButton);
        addPlayerButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        addPlayerButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                addPlayerButtonMouseClicked(evt);
            }
        });
        getContentPane().add(addPlayerButton);

        addEnemyButton.setAction(actionMap.get("addEnemy")); // NOI18N
        addEnemyButton.setIcon(resourceMap.getIcon("addEnemyButton.icon")); // NOI18N
        addEnemyButton.setText(resourceMap.getString("addEnemyButton.text")); // NOI18N
        addEnemyButton.setToolTipText(resourceMap.getString("addEnemyButton.toolTipText")); // NOI18N
        addEnemyButton.setFocusable(false);
        addEnemyButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        addEnemyButton.setMinimumSize(new java.awt.Dimension(40, 40));
        addEnemyButton.setName("addEnemyButton"); // NOI18N
        addEnemyButton.setNextFocusableComponent(addDoorButton);
        addEnemyButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        addEnemyButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                addPlayerButtonMouseClicked(evt);
            }
        });
        getContentPane().add(addEnemyButton);

        addDoorButton.setAction(actionMap.get("addDoor")); // NOI18N
        addDoorButton.setIcon(resourceMap.getIcon("addDoorButton.icon")); // NOI18N
        addDoorButton.setText(resourceMap.getString("addDoorButton.text")); // NOI18N
        addDoorButton.setToolTipText(resourceMap.getString("addDoorButton.toolTipText")); // NOI18N
        addDoorButton.setFocusable(false);
        addDoorButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        addDoorButton.setMinimumSize(new java.awt.Dimension(40, 40));
        addDoorButton.setName("addDoorButton"); // NOI18N
        addDoorButton.setNextFocusableComponent(addSpikeButton);
        addDoorButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        addDoorButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                addPlayerButtonMouseClicked(evt);
            }
        });
        getContentPane().add(addDoorButton);

        addSpikeButton.setAction(actionMap.get("addSpike")); // NOI18N
        addSpikeButton.setIcon(resourceMap.getIcon("addSpikeButton.icon")); // NOI18N
        addSpikeButton.setText(resourceMap.getString("addSpikeButton.text")); // NOI18N
        addSpikeButton.setToolTipText(resourceMap.getString("addSpikeButton.toolTipText")); // NOI18N
        addSpikeButton.setFocusable(false);
        addSpikeButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        addSpikeButton.setMinimumSize(new java.awt.Dimension(40, 40));
        addSpikeButton.setName("addSpikeButton"); // NOI18N
        addSpikeButton.setNextFocusableComponent(addLeverButton);
        addSpikeButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        addSpikeButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                addPlayerButtonMouseClicked(evt);
            }
        });
        getContentPane().add(addSpikeButton);

        addLeverButton.setAction(actionMap.get("addLeverSwitch")); // NOI18N
        addLeverButton.setIcon(resourceMap.getIcon("addLeverButton.icon")); // NOI18N
        addLeverButton.setText(resourceMap.getString("addLeverButton.text")); // NOI18N
        addLeverButton.setToolTipText(resourceMap.getString("addLeverButton.toolTipText")); // NOI18N
        addLeverButton.setMinimumSize(new java.awt.Dimension(40, 40));
        addLeverButton.setName("addLeverButton"); // NOI18N
        addLeverButton.setNextFocusableComponent(addPushButton);
        addLeverButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                addPlayerButtonMouseClicked(evt);
            }
        });
        getContentPane().add(addLeverButton);

        addPushButton.setAction(actionMap.get("addPush")); // NOI18N
        addPushButton.setIcon(resourceMap.getIcon("addPushButton.icon")); // NOI18N
        addPushButton.setText(resourceMap.getString("addPushButton.text")); // NOI18N
        addPushButton.setToolTipText(resourceMap.getString("addPushButton.toolTipText")); // NOI18N
        addPushButton.setFocusable(false);
        addPushButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        addPushButton.setMinimumSize(new java.awt.Dimension(40, 40));
        addPushButton.setName("addPushButton"); // NOI18N
        addPushButton.setNextFocusableComponent(addKeyButton);
        addPushButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        addPushButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                addPlayerButtonMouseClicked(evt);
            }
        });
        getContentPane().add(addPushButton);

        addKeyButton.setAction(actionMap.get("addKey")); // NOI18N
        addKeyButton.setIcon(resourceMap.getIcon("addKeyButton.icon")); // NOI18N
        addKeyButton.setText(resourceMap.getString("addKeyButton.text")); // NOI18N
        addKeyButton.setToolTipText(resourceMap.getString("addKeyButton.toolTipText")); // NOI18N
        addKeyButton.setFocusable(false);
        addKeyButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        addKeyButton.setMinimumSize(new java.awt.Dimension(40, 40));
        addKeyButton.setName("addKeyButton"); // NOI18N
        addKeyButton.setNextFocusableComponent(addBlueBoxButton);
        addKeyButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        addKeyButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                addPlayerButtonMouseClicked(evt);
            }
        });
        getContentPane().add(addKeyButton);

        addBlueBoxButton.setAction(actionMap.get("addTilltableObject")); // NOI18N
        addBlueBoxButton.setIcon(resourceMap.getIcon("addBlueBoxButton.icon")); // NOI18N
        addBlueBoxButton.setText(resourceMap.getString("addBlueBoxButton.text")); // NOI18N
        addBlueBoxButton.setToolTipText(resourceMap.getString("addBlueBoxButton.toolTipText")); // NOI18N
        addBlueBoxButton.setMinimumSize(new java.awt.Dimension(40, 40));
        addBlueBoxButton.setName("addBlueBoxButton"); // NOI18N
        addBlueBoxButton.setNextFocusableComponent(addRedBoxUpButton);
        addBlueBoxButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                addPlayerButtonMouseClicked(evt);
            }
        });
        getContentPane().add(addBlueBoxButton);

        addRedBoxUpButton.setAction(actionMap.get("addReverseGravitable")); // NOI18N
        addRedBoxUpButton.setIcon(resourceMap.getIcon("addRedBoxUpButton.icon")); // NOI18N
        addRedBoxUpButton.setText(resourceMap.getString("addRedBoxUpButton.text")); // NOI18N
        addRedBoxUpButton.setToolTipText(resourceMap.getString("addRedBoxUpButton.toolTipText")); // NOI18N
        addRedBoxUpButton.setMinimumSize(new java.awt.Dimension(40, 40));
        addRedBoxUpButton.setName("addRedBoxUpButton"); // NOI18N
        addRedBoxUpButton.setNextFocusableComponent(addRedBoxDownButton);
        addRedBoxUpButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                addPlayerButtonMouseClicked(evt);
            }
        });
        getContentPane().add(addRedBoxUpButton);

        addRedBoxDownButton.setAction(actionMap.get("addGravitable")); // NOI18N
        addRedBoxDownButton.setIcon(resourceMap.getIcon("addRedBoxDownButton.icon")); // NOI18N
        addRedBoxDownButton.setText(resourceMap.getString("addRedBoxDownButton.text")); // NOI18N
        addRedBoxDownButton.setToolTipText(resourceMap.getString("addRedBoxDownButton.toolTipText")); // NOI18N
        addRedBoxDownButton.setMinimumSize(new java.awt.Dimension(40, 40));
        addRedBoxDownButton.setName("addRedBoxDownButton"); // NOI18N
        addRedBoxDownButton.setNextFocusableComponent(addWoodenBoxButton);
        addRedBoxDownButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                addPlayerButtonMouseClicked(evt);
            }
        });
        getContentPane().add(addRedBoxDownButton);

        addWoodenBoxButton.setAction(actionMap.get("addStationaryObstacle")); // NOI18N
        addWoodenBoxButton.setIcon(resourceMap.getIcon("addWoodenBoxButton.icon")); // NOI18N
        addWoodenBoxButton.setText(resourceMap.getString("addWoodenBoxButton.text")); // NOI18N
        addWoodenBoxButton.setToolTipText(resourceMap.getString("addWoodenBoxButton.toolTipText")); // NOI18N
        addWoodenBoxButton.setMinimumSize(new java.awt.Dimension(40, 40));
        addWoodenBoxButton.setName("addWoodenBoxButton"); // NOI18N
        addWoodenBoxButton.setNextFocusableComponent(changeBackgroundComboBox);
        addWoodenBoxButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                addPlayerButtonMouseClicked(evt);
            }
        });
        getContentPane().add(addWoodenBoxButton);

        changeBackgroundComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "No bg", "Clouds", "Lava" }));
        changeBackgroundComboBox.setToolTipText(resourceMap.getString("changeBackgroundComboBox.toolTipText")); // NOI18N
        changeBackgroundComboBox.setName("changeBackgroundComboBox"); // NOI18N
        changeBackgroundComboBox.setNextFocusableComponent(addPlayerButton);
        changeBackgroundComboBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                changeBackgroundComboBoxActionPerformed(evt);
            }
        });
        getContentPane().add(changeBackgroundComboBox);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void changeBackgroundComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_changeBackgroundComboBoxActionPerformed
        levelModel.removeBackground();
        if (changeBackgroundComboBox.getSelectedIndex()==1)
            levelModel.setBackground(GameObjectFactory.createGameObject(GameObjectFactory.
                    GameObjectType.Scenery, new Point(0,0), new Bitmap("@drawable/background"), 4));
        else if (changeBackgroundComboBox.getSelectedIndex()==2)
            levelModel.setBackground(GameObjectFactory.createGameObject(GameObjectFactory.
                    GameObjectType.Scenery, new Point(0,0), new Bitmap("@drawable/lava_background"), 4));

        levelModel.getView().repaintAll();
}//GEN-LAST:event_changeBackgroundComboBoxActionPerformed

    private void addPlayerButtonMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_addPlayerButtonMouseClicked
        GameObjectType type = null;
        String bitmapSource = "";
        int layer = 1;
        if (evt.getSource().equals(addPlayerButton))
            type=GameObjectType.PlayerObject;
        else if (evt.getSource().equals(addEnemyButton))
            type=GameObjectType.Enemy;
        else if (evt.getSource().equals(addDoorButton))
            type=GameObjectType.Door;
        else if (evt.getSource().equals(addKeyButton))
            type=GameObjectType.Key;
        else if (evt.getSource().equals(addSpikeButton))
            type=GameObjectType.Spike;
        else if (evt.getSource().equals(addBlueBoxButton))
            type=GameObjectType.TiltableObject;
        else if (evt.getSource().equals(addRedBoxUpButton))
            type=GameObjectType.ReverseGravitable;
        else if (evt.getSource().equals(addRedBoxDownButton))
            type=GameObjectType.Gravitable;
        else if (evt.getSource().equals(addLeverButton))
            type=GameObjectType.Lever;
        else if (evt.getSource().equals(addPushButton))
            type=GameObjectType.Push;
        else if (evt.getSource().equals(addWoodenBoxButton))
            type=GameObjectType.StationaryObstacle;
        if (type!=null){
        switch(type){
            case PlayerObject:
                bitmapSource="@drawable/player";
                break;
            case Enemy:
                bitmapSource="@drawable/enemy3";
                break;
            case Door:
                 bitmapSource="@drawable/door2";
                 layer=3;
                 break;
            case Key:
                 bitmapSource="@drawable/key";
                 layer=0;
                 break;
            case Spike:
                 bitmapSource="@drawable/spikes";
                 break;
            case TiltableObject:
                 bitmapSource="@drawable/bluebox";
                 break;
            case ReverseGravitable:
                 bitmapSource="@drawable/redbox_up";
                 break;
            case Gravitable:
                 bitmapSource="@drawable/redbox_down";
                 break;
            case StationaryObstacle:
                 bitmapSource="@drawable/woodenbox";
                 break;
            case Push:
                 bitmapSource="@drawable/push_switch";
                 break;
            case Lever:
                 bitmapSource="@drawable/lever_switch";
                 break;
        }
        if (!(type.equals(GameObjectType.PlayerObject) && levelModel.containsPlayer()))
        {
            levelModel.addObject(GameObjectFactory.createGameObject(type, new Point(240,170),
                    new Bitmap(bitmapSource), layer));
            levelModel.getView().repaintAll();
        }
        }

    }//GEN-LAST:event_addPlayerButtonMouseClicked

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new JObjectPaletteFrame().setVisible(true);
            }
        });
    }


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton addBlueBoxButton;
    private javax.swing.JButton addDoorButton;
    private javax.swing.JButton addEnemyButton;
    private javax.swing.JButton addKeyButton;
    private javax.swing.JButton addLeverButton;
    private javax.swing.JButton addPlayerButton;
    private javax.swing.JButton addPushButton;
    private javax.swing.JButton addRedBoxDownButton;
    private javax.swing.JButton addRedBoxUpButton;
    private javax.swing.JButton addSpikeButton;
    private javax.swing.JButton addWoodenBoxButton;
    private javax.swing.JComboBox changeBackgroundComboBox;
    // End of variables declaration//GEN-END:variables

}
